home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / gcc / ixemlsrc.lha / ixemul / ixnet / lrucache.h < prev    next >
C/C++ Source or Header  |  1996-03-13  |  4KB  |  117 lines

  1. #ifndef _LRUCACHE_H_
  2. #define _LRUCACHE_H_
  3.  
  4. /*-
  5.  * Copyright (c) 1990 The Regents of the University of California.
  6.  * All rights reserved.
  7.  *
  8.  * This code is derived from software contributed to Berkeley by
  9.  * Mike Olson.
  10.  *
  11.  * Redistribution and use in source and binary forms, with or without
  12.  * modification, are permitted provided that the following conditions
  13.  * are met:
  14.  * 1. Redistributions of source code must retain the above copyright
  15.  *    notice, this list of conditions and the following disclaimer.
  16.  * 2. Redistributions in binary form must reproduce the above copyright
  17.  *    notice, this list of conditions and the following disclaimer in the
  18.  *    documentation and/or other materials provided with the distribution.
  19.  * 3. All advertising materials mentioning features or use of this software
  20.  *    must display the following acknowledgement:
  21.  *    This product includes software developed by the University of
  22.  *    California, Berkeley and its contributors.
  23.  * 4. Neither the name of the University nor the names of its contributors
  24.  *    may be used to endorse or promote products derived from this software
  25.  *    without specific prior written permission.
  26.  *
  27.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  28.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  30.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  31.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  33.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  34.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  35.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  36.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  37.  * SUCH DAMAGE.
  38.  */
  39.  
  40. /*
  41.  * @(#)lrucache.h    5.1 (Berkeley) 1/23/91
  42.  */
  43.  
  44. /*
  45.  *  LRU list entries.  The head of the list is the most-recently requested
  46.  *  block; the tail is the least-recently requested one.
  47.  */
  48.  
  49. typedef struct LRU_ENT {
  50.     char    *l_buffer;        /* buffer we return to user */
  51.     int    l_pgno;            /* logical page number */
  52.     int    l_flags;        /* FREE and DIRTY bits */
  53.     struct LRU_ENT    *l_prev;    /* predecessor in LRU list */
  54.     struct LRU_ENT    *l_next;    /* successor in LRU list */
  55. } LRU_ENT;
  56.  
  57. /*
  58.  *  Cache entries.  We use a hash table to avoid a linear walk of the LRU
  59.  *  list when we need to look up blocks by number.  The hash table is
  60.  *  chained.
  61.  */
  62.  
  63. typedef struct CACHE_ENT {
  64.     int            c_pgno;
  65.     LRU_ENT            *c_lruent;
  66.     struct CACHE_ENT    *c_chain;
  67. } CACHE_ENT;
  68.  
  69. /*
  70.  *  The LRU cache structure.  The cache size (lru_csize) is the largest size
  71.  *  the user wants us to grow to; current size (lru_cursz) is always less than
  72.  *  or equal to lru_csize.  Note that we will grow the cache (lru_csize) if
  73.  *  it's the only way that we can satisfy a user's block request.
  74.  */
  75.  
  76. typedef struct LRUCACHE {
  77.     int        lru_fd;
  78.     int        lru_csize;
  79.     int        lru_psize;
  80.     int        lru_cursz;
  81.     char        *lru_opaque;        /* passed to inproc, outproc */
  82.     int        (*lru_inproc)();
  83.     int        (*lru_outproc)();
  84.     LRU_ENT        *lru_head;
  85.     LRU_ENT        *lru_tail;
  86.     CACHE_ENT    **lru_cache;
  87. } LRUCACHE;
  88.  
  89. #ifndef NULL
  90. #define NULL    0
  91. #endif /* ndef NULL */
  92.  
  93. /* this is the opaque type we return for LRU caches */
  94. typedef    char    *LRU;
  95.  
  96. /* bits for l_flags in LRU_ENT structure */
  97. #define LRU_DIRTY      (1 << 0)
  98. #define LRU_FREE      (1 << 1)
  99.  
  100. /* lru module routines */
  101. extern CACHE_ENT    *lruhashget(LRUCACHE *, int);
  102. extern CACHE_ENT    *lruhashput(LRUCACHE *, int, LRU_ENT *);
  103. extern int        lruhashdel(LRUCACHE *, int);
  104. extern void        lruhead(LRUCACHE *,LRU_ENT *);
  105. extern int        lrugrow(LRUCACHE *);
  106. extern LRU        lruinit(int, int, int, char *, int (*)(), int(*)());
  107. extern int        lruwrite(LRU, int);
  108. extern int        lrusync(LRU);
  109. extern char        *lruget(LRU, int, int *);
  110. extern char        *lrugetnew(LRU, int ,int *);
  111. extern char        *lrugetpg(LRUCACHE *, int, int *, char *(*)());
  112. extern int        lrurelease(LRU, int);
  113. extern void        lrufree(LRU);
  114. extern int        lruflush(LRUCACHE *, LRU_ENT *);
  115.  
  116. #endif
  117.